package newtank.view.context;

import entity.Direction;
import entity.MoveGenerator;
import entity.Position;
import lombok.Data;
import lombok.SneakyThrows;

/**
 * @author lijiahao
 * @since 2022/3/18
 */
@Data
public class BulletViewContext implements ModelViewContext, Runnable {

    /**
     * 位置
     */
    private Position position;

    /**
     * 方向
     */
    private Direction direction;

    /**
     * 速度
     */
    private int speed;

    /**
     * 存活状态
     */
    private boolean alive;

    /**
     * 坦克信息
     */
    private TankViewContext tankViewContext;

    /**
     * 唯一码
     */
    private String unique;

    @SneakyThrows
    @Override
    public void run() {
        while(alive) {
            if(Position.isOverRound(this.position)) {
                alive = false;
            } else {
                Thread.sleep(20);
                MoveGenerator.move(this.position, this.direction, this.speed, this.getClass());
            }
        }
    }

    @Override
    public boolean isAlive() {
        return alive;
    }

    @Override
    public void dieOut() {
        this.alive = false;
    }

    @Override
    public int getVersion() {
        return 0;
    }
}
